﻿using System;
using System.IO;
using ProjScan.Config;
using ProjScan.RecordManager;
using ProjScan.ScanGUI;
using ProjScan.ScanRule;
using ProjScan.ScanRule.Attr;
using ProjScan.Submodules.Art_Assets_Check;
using ProjScan.Tools;

namespace ProjScan.Modules
{
	// Token: 0x020002FF RID: 767
	internal class ArtAssetsCheckModule : BaseModules<ArtAssetsCheckModule, ArtAssetsCheckConfig>
	{
		// Token: 0x06001229 RID: 4649 RVA: 0x00053F98 File Offset: 0x00052198
		public override void Run(StreamWriter ruleStreamWriter, StreamWriter thresholdStreamWriter)
		{
			Singleton<PerformanceMeasurer>.Instance.PushState("Art_Assets_Check");
			ScanLog.Instance.LogInfo(Module.Art_Assets_Check, "Run");
			ToolsHelper.ShowProgressBar("Art Assets Check", "Initializing...", 0.01f, false);
			this.rulesSw = ruleStreamWriter;
			this.thresSw = thresholdStreamWriter;
			this.Init();
			this.LoadRules(LoadMode.Check);
			bool flag = this.baseRules_Check == null || this.baseRules_Check.Count == 0;
			if (flag)
			{
				ScanLog.Instance.LogInfo(Module.Basic_Assets_Check, ScanLog.Stage.s2, "Rules is empty");
				ScanLog.UnityLogError("美术资源检测运行失败：相关规则全部关闭");
				this.Close();
			}
			else
			{
				this.InitRules(8000);
				RecordManagerFactory.Instance.RecordRuleInit(this.recordRules_Check);
				try
				{
					RecordManagerFactory.Instance.PrepareAssets();
				}
				catch (Exception ex)
				{
					ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.Basic_Assets_Check, ScanLog.Stage.s2, "ScanAll", string.Concat(new string[]
					{
						ex.GetType().FullName,
						" ",
						ex.Message,
						"\n",
						ex.StackTrace
					}));
					this.Close();
					this.DeleteOutputFiles();
					Singleton<ScanOverviewManager>.Instance.SetModulesRunError("Art_Assets_Check");
					return;
				}
				for (int i = 0; i < this.recordRules_Check.Count; i++)
				{
					RecordRule recordRule = this.recordRules_Check[i];
					ToolsHelper.ShowProgressBar("Output data", string.Format("Scan:{0}({1}/{2})", recordRule.GetType().Name, i + 1, this.recordRules_Check.Count), 0.5f * (float)(i + 1) / (float)this.recordRules_Check.Count, false);
					recordRule.OutputData(false);
					recordRule.OutputDetailData();
					recordRule.DumpToRuleCSV(ref this.rulesSw);
					recordRule.DumpToThresCSV(ref this.thresSw);
				}
				ScanLog.Instance.LogInfo(Module.Art_Assets_Check, ScanLog.Stage.s4, "Done.");
				RecordManagerFactory.Instance.OutPutScanScr();
				ScanLog.Instance.LogInfo(Module.Art_Assets_Check, ScanLog.Stage.s5, "Done.");
				RecordManagerFactory.Instance.Close();
				this.Close();
			}
		}

		// Token: 0x0600122A RID: 4650 RVA: 0x000541E4 File Offset: 0x000523E4
		public override void Init()
		{
			this.config = (Singleton<ConfigMgr>.Instance.GetConfig<ArtAssetsCheckConfig>() as ArtAssetsCheckConfig);
			ShaderUtility.Initialize();
			this.baseRules_Check.Clear();
			this.recordRules_Check.Clear();
			this.globalRules_Check.Clear();
			this.ruleAttr = typeof(ArtAssetRuleAttr);
			RecordManagerFactory.Instance.Init();
		}

		// Token: 0x0600122B RID: 4651 RVA: 0x0000880C File Offset: 0x00006A0C
		public override void Close()
		{
			Singleton<PerformanceMeasurer>.Instance.CloseAndRecordState();
			Singleton<PerformanceMeasurer>.Instance.AddExecutionCheckpoint("ArtAssetsCheckEnd");
			ScanLog.Instance.LogInfo(Module.Art_Assets_Check, ScanLog.Stage.s6, "Done.");
		}
	}
}
